package com.twu.biblioteca;

import com.twu.biblioteca.book.BookManager;
import com.twu.biblioteca.exception.InvalidSelectionException;
import com.twu.biblioteca.movie.MovieManager;

import java.io.*;

public class BibliotecaApp {
    private Library library;

    public static void main(String[] args) throws Exception {
        BibliotecaApp bibliotecaApp = new BibliotecaApp();
        bibliotecaApp.init(null, null);
        bibliotecaApp.run();
    }

    public void init(InputStream inputStream, OutputStream outputStream) {
        library = new Library(new BookManager(), new MovieManager());
        library.setIO(inputStream, outputStream);
        library.showMessage("Hello, welcome to Biblioteca!");
    }

    public void run() throws IOException {
        library.showOptions();
        while (!library.isQuit()) {
            String option = library.getMessage();
            try {
                library.executeOption(option);
            } catch (InvalidSelectionException e) {
                library.showMessage(e.getMessage());
            }catch (Exception e) {
                library.showMessage(e.getMessage());
            }
        }
    }
}


